package apk;

import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;

import java.io.File;

/**
 * @Author zhangtao
 * @create 2022/2/17 14:09
 */
@Slf4j
public class ApkParse {
    public static void main(String[] args) {
        try {
            File file = new File("C:\\Users\\Administrator\\Downloads\\apkpurev3.17.26_downcc.com.apk");
            if (file.exists() && file.isFile()) {
                ApkFile apkFile = new ApkFile(file);
                ApkMeta apkMeta = apkFile.getApkMeta();
                System.out.println("应用名称 :" + apkMeta.getLabel());
                System.out.println("包名     :" + apkMeta.getPackageName());
                System.out.println("版本号   :" + apkMeta.getVersionName());
                System.out.println("图标     :" + apkMeta.getIcon());
                System.out.println("大小     :" + (double) (file.length() * 100 / 1024 / 1024) / 100 + " MB");
                //注释：apk所有信息都在apkMeta类里面。可以输出整个apkMeta来查看跟多详情信息
                log.info("apk信息：{}", new Gson().toJson(apkMeta));

                apkFile.getApkSingers().forEach(s -> s.getCertificateMetas().forEach(c -> log.info("v1证书：{}", c.toString())));
                apkFile.getApkV2Singers().forEach(s -> s.getCertificateMetas().forEach(c -> log.info("v2证书：{}", c.toString())));
                log.info("ManifestXml:{}", apkFile.getManifestXml());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
